<?PHP
if (!session_start()) { session_start(); }

if (isset($_POST['submit'])) {
	if ($_POST['un']=='dc' && $_POST['pw']=='AVADfend3r') {
		$_SESSION['lgn']=$_POST['pw'];
	}	
}
if (isset($_SESSION['lgn']) && $_SESSION['lgn']=="AVADfend3r") {
// Define database connection constants
	define('DB_HOST', 'localhost');
	define('DB_USER', 'phillipv_user1');
	define('DB_PASSWORD', 'pas');
	define('DB_NAME', 'phillipv_AVA');
	
	/*define('DB_USER', 'root');
	define('DB_PASSWORD', 'SQLfender');
	define('DB_NAME', 'masterlog');*/
	
	define('CURRENT_SEASON', '2009');
	
	$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.');
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?PHP
$dbfieldname='Tables_in_'.DB_NAME;
if (isset($_SESSION['lgn']) && $_SESSION['lgn']=="AVADfend3r") {
	
	$SQLtables='SHOW TABLES';
	$sendtables=mysqli_query($dbc,$SQLtables) or die(mysqli_error($dbc));
	while ($RStables=mysqli_fetch_object($sendtables)) {
		//Create Table Query
		$createTabler='CREATE TABLE ';
		$primareyKeyVar='';
		
		//Get Data Query
		$commaSeperatedData='';
		
		$tempArray=array();
		$tempCount=0;
		print '<p><strong>'.$RStables->$dbfieldname.'</strong></p>';
		//print '<p><a href="getdata.php?tn='.$RStables->$dbfieldname.'">GET DATA</a></p>';
		//Create Table Query
		$createTabler=$createTabler.$RStables->$dbfieldname.' (';
		print '<table><tr>';
		$SQLtd='DESCRIBE '.$RStables->$dbfieldname.';';
		$sendtd=mysqli_query($dbc,$SQLtd) or die($dbc);
		while ($RStd = mysqli_fetch_object($sendtd)) {
			$tempArray[]=$RStd->Field;
			$tempCount++;
			print '<td>'.$RStd->Field.', '.$RStd->Type.', '.$RStd->Key.'</td>';
			//Create Table Query
			$createTabler=$createTabler.$RStd->Field.' '.$RStd->Type.', ';
			if ($RStd->Key=='PRI') {
				$primareyKeyVar=$RStd->Field;
			}
		}
		print '</tr>';
		$SQLrec='SELECT * FROM '.$RStables->$dbfieldname.';';
		$sendrec=mysqli_query($dbc,$SQLrec) or die($dbc);
		while ($RSrec=mysqli_fetch_object($sendrec)) {
			print '<tr>';
			foreach ($tempArray as $key=>$value) { print '<td>'.$RSrec->$value.'</td>'; }
			foreach ($tempArray as $key=>$value) { $commaSeperatedData=$commaSeperatedData.$RSrec->$value.','; }
			print '</tr>';
			$commaSeperatedData=(rtrim($commaSeperatedData, ",")).'<br />';
		}
		print '</table>';
		//Create Table Query
		$createTabler=$createTabler.' PRIMARY KEY ('.$primareyKeyVar.'));';
		print '<p>'.$createTabler.'</p>';
		print $commaSeperatedData;
	}

} else {
?>
<form id="loginform" method="post" action="checkdb.php">
<p><input type="" name="un" /> <input type="password" name="pw" /></p>
<p><input type="submit" name="submit" value=" Go "</p>
</form>

<?PHP
}
?>

</body>
</html>
<?PHP
if (isset($_SESSION['lgn']) && $_SESSION['lgn']=="AVADfend3r") {
	mysqli_close($dbc);
}
?>